package javolution.xml;

import java.io.InputStream;
import java.io.Reader;
import javolution.context.ObjectFactory;
import javolution.lang.Reusable;
import javolution.xml.XMLFormat;
import javolution.xml.stream.XMLStreamException;
import javolution.xml.stream.XMLStreamReader;

/* loaded from: classes2.dex */
public class XMLObjectReader implements Reusable {
    private static final ObjectFactory FACTORY = new ObjectFactory() { // from class: javolution.xml.XMLObjectReader.1
        /* JADX INFO: Access modifiers changed from: protected */
        @Override // javolution.context.ObjectFactory
        public void cleanup(Object obj) {
            ((XMLObjectReader) obj).reset();
        }

        /* JADX INFO: Access modifiers changed from: protected */
        @Override // javolution.context.ObjectFactory
        public Object create() {
            return new XMLObjectReader();
        }
    };
    private InputStream _inputStream;
    private boolean _isFactoryProduced;
    private Reader _reader;
    private final XMLFormat.InputElement _xml = new XMLFormat.InputElement();

    public static XMLObjectReader newInstance(InputStream inputStream) throws XMLStreamException {
        XMLObjectReader xMLObjectReader = (XMLObjectReader) FACTORY.object();
        xMLObjectReader._isFactoryProduced = true;
        xMLObjectReader.setInput(inputStream);
        return xMLObjectReader;
    }

    public static XMLObjectReader newInstance(InputStream inputStream, String str) throws XMLStreamException {
        XMLObjectReader xMLObjectReader = (XMLObjectReader) FACTORY.object();
        xMLObjectReader._isFactoryProduced = true;
        xMLObjectReader.setInput(inputStream, str);
        return xMLObjectReader;
    }

    public static XMLObjectReader newInstance(Reader reader) throws XMLStreamException {
        XMLObjectReader xMLObjectReader = (XMLObjectReader) FACTORY.object();
        xMLObjectReader._isFactoryProduced = true;
        xMLObjectReader.setInput(reader);
        return xMLObjectReader;
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x001b A[Catch: IOException -> 0x0021, TRY_LEAVE, TryCatch #0 {IOException -> 0x0021, blocks: (B:2:0x0000, B:4:0x0004, B:5:0x0009, B:9:0x0017, B:11:0x001b, B:6:0x000d, B:8:0x0011), top: B:17:0x0000 }] */
    /* JADX WARN: Removed duplicated region for block: B:19:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void close() throws javolution.xml.stream.XMLStreamException {
        /*
            r2 = this;
            java.io.InputStream r0 = r2._inputStream     // Catch: java.io.IOException -> L21
            if (r0 == 0) goto Ld
            java.io.InputStream r0 = r2._inputStream     // Catch: java.io.IOException -> L21
            r0.close()     // Catch: java.io.IOException -> L21
        L9:
            r2.reset()     // Catch: java.io.IOException -> L21
            goto L17
        Ld:
            java.io.Reader r0 = r2._reader     // Catch: java.io.IOException -> L21
            if (r0 == 0) goto L17
            java.io.Reader r0 = r2._reader     // Catch: java.io.IOException -> L21
            r0.close()     // Catch: java.io.IOException -> L21
            goto L9
        L17:
            boolean r0 = r2._isFactoryProduced     // Catch: java.io.IOException -> L21
            if (r0 == 0) goto L20
            javolution.context.ObjectFactory r0 = javolution.xml.XMLObjectReader.FACTORY     // Catch: java.io.IOException -> L21
            r0.recycle(r2)     // Catch: java.io.IOException -> L21
        L20:
            return
        L21:
            r0 = move-exception
            javolution.xml.stream.XMLStreamException r1 = new javolution.xml.stream.XMLStreamException
            r1.<init>(r0)
            goto L29
        L28:
            throw r1
        L29:
            goto L28
        */
        throw new UnsupportedOperationException("Method not decompiled: javolution.xml.XMLObjectReader.close():void");
    }

    public XMLStreamReader getStreamReader() {
        return this._xml._reader;
    }

    public boolean hasNext() throws XMLStreamException {
        return this._xml.hasNext();
    }

    public <T> T read() throws XMLStreamException {
        return (T) this._xml.getNext();
    }

    public <T> T read(String str) throws XMLStreamException {
        return (T) this._xml.get(str);
    }

    public <T> T read(String str, Class<T> cls) throws XMLStreamException {
        return (T) this._xml.get(str, cls);
    }

    public <T> T read(String str, String str2) throws XMLStreamException {
        return (T) this._xml.get(str, str2);
    }

    public <T> T read(String str, String str2, Class<T> cls) throws XMLStreamException {
        return (T) this._xml.get(str, str2, cls);
    }

    @Override // javolution.lang.Reusable
    public void reset() {
        this._xml.reset();
        this._reader = null;
        this._inputStream = null;
    }

    public XMLObjectReader setBinding(XMLBinding xMLBinding) {
        this._xml.setBinding(xMLBinding);
        return this;
    }

    public XMLObjectReader setInput(InputStream inputStream) throws XMLStreamException {
        if (this._inputStream == null && this._reader == null) {
            this._xml._reader.setInput(inputStream);
            this._inputStream = inputStream;
            return this;
        }
        throw new IllegalStateException("Reader not closed or reset");
    }

    public XMLObjectReader setInput(InputStream inputStream, String str) throws XMLStreamException {
        if (this._inputStream == null && this._reader == null) {
            this._xml._reader.setInput(inputStream, str);
            this._inputStream = inputStream;
            return this;
        }
        throw new IllegalStateException("Reader not closed or reset");
    }

    public XMLObjectReader setInput(Reader reader) throws XMLStreamException {
        if (this._inputStream == null && this._reader == null) {
            this._xml._reader.setInput(reader);
            this._reader = reader;
            return this;
        }
        throw new IllegalStateException("Reader not closed or reset");
    }

    public XMLObjectReader setReferenceResolver(XMLReferenceResolver xMLReferenceResolver) {
        this._xml.setReferenceResolver(xMLReferenceResolver);
        return this;
    }
}
